package cn.gok.qqclient.controllers;

import cn.gok.qqclient.beans.Page;
import cn.gok.qqclient.beans.Province;
import cn.gok.qqclient.beans.ReturnData;
import cn.gok.qqclient.services.ProvinceService;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class ShowDataController {

    @Autowired
    private ProvinceService provinceService;

    @RequestMapping("/getData")
    public String getData(HttpServletRequest request){
        //接收前端的分页数据
        String nowPage = request.getParameter("page");
        String pageSize = request.getParameter("limit");

        System.out.println(nowPage+"  "+pageSize);

        //设置分页信息
        Page page=new Page(Integer.parseInt(nowPage),Integer.parseInt(pageSize));

        PageInfo<Province> dataBypage = provinceService.getDataBypage(page);


        ReturnData returnData=new ReturnData();
        returnData.setCode(0);
        returnData.setCount(provinceService.getAllData().size());
        returnData.setData(dataBypage.getList());
        return JSON.toJSONString(returnData);
    }


}
